import {
    nextTick,
    msg,
    open,
    setPageNumber,
    confirm,
    close
} from '../../common/utils.js';
import Vue from 'vue';
import {
    serverPath,
    json,
    currentPath
} from '../../common/config.js';
import RoleService from '../services/roleService.js';

window.Module = function () {
    let roleService = new RoleService();
    return new Vue({
        el: '#indexController',
        data: {
            list: []
        },
        methods: {
            init: async function () {
                await this.loadData();
            },
            pageChange: async function (pageIndex, e) {
                this.pager.pageIndex = pageIndex;
                await this.loadData();
            },
            loadData: async function () {
                let res = await roleService.queryRole();

                if (!res.type) {
                    return;
                }
                else if (json === res.type) {
                    var response = res.body;
                    if ('Success' === response.result) {
                        this.list = response.data;
                    }
                    else {
                        await msg(response.message);
                    }
                }
            },
            selectRole:function(item){
                parent.result = item;
                close();
            }
        }
    });
};